xlv.imp.ajax={
	implement:function(){
	},
	method:{
		ajax_properties:{
			request:null,
			url:'',
			options:{
				postBody:null,
			    evalJSON:false,
			    evalJS:false,
			    requestHeaders:{
					'X-XLive-Version':xlv.version,
					'X-XLive-Content':'xml'
				}
			}
		},
		ajax_request:function(url,options){
			var p=this.ajax_properties;
			p.url=url||p.url;
			if(!p.options.onComplete){
				var po=this.ajax_properties.options;
				po.onException=this.ajax_onException.bind(this);
				po.onCreate=this.ajax_onCreate.bind(this);
				po.onUninitialized=this.ajax_onUninitialized.bind(this);
				po.onLoading=this.ajax_onLoading.bind(this);
				po.onLoaded=this.ajax_onLoaded.bind(this);
				po.onInteractive=this.ajax_onInteractive.bind(this);
				po.onComplete=this.ajax_onComplete.bind(this);
				po.onSuccess=this.ajax_onSuccess.bind(this);
				po.onFailure=this.ajax_onFailure.bind(this);
			}
			if(xlv.sys.xSessionId){
				p.options.requestHeaders.xsessionid=xlv.sys.xSessionId;
			}
			Object.extend(p.options, options||{});
			/*
			if(window.netscape && window.netscape.security.PrivilegeManager.enablePrivilege){
				window.netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
			}
			*/
			p.request=new Ajax.Request(p.url,p.options);
		},
		ajax_readyState:function(){
			var r=this.ajax_properties.request;
			return (r ? r.transport.readyState : null);
		},
		ajax_onException:function(aR,aEXP){
			if(!aR || !aR.transport){
				alert('Request Error: '+aEXP);
				return;
			}
			var t=aR.transport;
			if(!t.status) alert('EXP status : '+aEXP);
			else if(t.status<200 ||t.status>=300)
	 				alert("ajax exception: "+aEXP+"\nstatus: "+aR.transport.status+"\nreadyState: "+aR.transport.readyState);
		},
		ajax_onCreate:function(aT,aJ){//aT:transporter, aJ:JSON
		},
		ajax_onUninitialized:function(aT,aJ){
		},
		ajax_onLoading:function(aT,aJ){
		},
		ajax_onLoaded:function(aT,aJ){
		},
		ajax_onInteractive:function(aT,aJ){
		},
		ajax_onComplete:function(aT,aJ){
			var xid=aT.transport.getResponseHeader('xsessionid');
			if(xid) {
				if(xid && xlv.sys.xSessionId && xlv.sys.xSessionId != xid && xlv.sessionControl) {
					alert('session lost /nxid :'+xid+'\nxSessionId :'+xlv.sys.xSessionId);
					clearInterval(xlv.timeout.handler);
					if(xlv.desktop) xlv.sys.dispose(xlv.desktop,true);
			    	if(window.removeEventListener) window.removeEventListener('unload', xlv.dispose, false);
			    	else if(window.detachEvent) window.detachEvent('onunload', xlv.dispose);
			    	return;
				}
				xlv.sys.xSessionId=xid;
			}
			var url = this.ajax_properties.url.toLowerCase();
			if(!url.endsWith('.html')&& !url.endsWith('.htm'))xlv.timeout.lastTime= new Date().getTime();
		},
		ajax_onSuccess:function(aT,aJ){
			this.ajax_response(aT,aJ);
		},
		ajax_onFailure:function(aT,aJ){
			var msg="ajax completed but failure: "+(aT)?("\nstatus: "+aT.status+"\nreadyState: "+aT.readyState) : "";
			alert(msg);
		},
		ajax_response:function(aT,aJ){
		}
	}
};

